package hospital.order.api;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import hospital.enums.OrderStatusEnum;
import hospital.model.order.OrderInfo;
import hospital.order.service.OrderService;
import hospital.result.Result;
import hospital.utils.AuthContextHolder;
import hospital.vo.order.OrderCountQueryVo;
import hospital.vo.order.OrderQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author
 * @description:
 * @create 2023/4/1-15:30
 */
@Api("创建订单接口")
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderApiController {
    @Autowired
    private OrderService orderService;

    /**
     * @Author yang
     * @Description //TODO 生成挂号订单
     * @Date 15:38 2023/4/30
     * @Param
     * @return
     **/
    @PostMapping("auth/submitOrder/{scheduleId}/{patientId}")
    public Result savaOrders(@PathVariable String scheduleId,
                             @PathVariable Long patientId) {
        System.out.println("排班id"+scheduleId+" 病人"+patientId);
        Long orderId = orderService.saveOrder(scheduleId,patientId);
        return Result.ok(orderId);
    }

    /**
     * @Author yang
     * @Description //TODO 获取订单详情
     * @Date 18:17 2023/4/1
     * @Param
     * @return
     **/
    @GetMapping("/auth/getOrders/{orderId}")
    public Result getOrderInfo(@PathVariable String orderId){
        OrderInfo orderInfo=orderService.getOrderInfo(orderId);
        return Result.ok(orderInfo);
    }

    /**
     * @Author yang
     * @Description //TODO 获取订单列表
     * @Date 18:29 2023/4/1
     * @Param
     * @return
     **/
    @ApiOperation("获取订单列表")
    @GetMapping("/auth/{page}/{limit}")
    public Result getPageList(@PathVariable Integer page,
                              @PathVariable Integer limit,
                              OrderQueryVo orderQueryVo,
                              HttpServletRequest request){
        //从header中查询出userID
        Long userId = AuthContextHolder.getUserId(request);
        Page<OrderInfo> infoPage=orderService.getPageList(page,limit,userId,orderQueryVo);
        return Result.ok(infoPage);
    }

    /**
     * @Author yang
     * @Description //TODO 获取所有的订单状态
     * @Date 18:30 2023/4/1
     * @Param 
     * @return 
     **/
    @ApiOperation("获取所有的订单状态")
    @GetMapping("/auth/getStatusList")
    public Result getStatusList(){
        return Result.ok(OrderStatusEnum.getStatusList());
    }

    /**
     * @Author yang
     * @Description //TODO 取消预约
     * @Date 22:25 2023/4/1
     * @Param
     * @return
     **/
    @GetMapping("auth/cancelOrder/{orderId}")
    public Result cancelOrder(@PathVariable Long orderId) {
        Boolean isOrder = orderService.cancelOrder(orderId);
        return Result.ok(isOrder);
    }

    /**
     * @Author yang
     * @Description //TODO 获取订单数据，用户后台的数据分析
     * @Date 21:45 2023/4/2
     * @Param [orderCountQueryVo]
     * @return
     **/
    @ApiOperation("获取订单数据，用户后台的数据分析")
    @PostMapping("inner/getCountMap")
    public Map<String, Object> getCountMap(OrderCountQueryVo orderCountQueryVo){
        Map<String, Object> countMap = orderService.getCountMap(orderCountQueryVo);
        return countMap;
    }
}
